import React, { Component } from 'react'
import {
  SchemaForm, Item, ErrorList, Observer
} from '@amazebird/antd-schema-form'
// import style from './style.less'nstants/param-config'
export const BIG_MOUNTH_ARR = [1, 3, 5, 7, 8, 10, 12]

export const CONFIG_TYPE_MAP = {
  1: '12+0编制',
  2: '3+9编制',
  3: '6+6编制',
  4: '9+3编制',
  5: '上年度在编'
}

export default class ConfigSync extends Component {
  schema: any = {
    configSyncRolist: {
      type: 'array',
      item: {
        type: 'object',
        label: ({ index }) => CONFIG_TYPE_MAP[index + 1],
        fields: {
          monthNum: {
            component: 'Select',
            required: true,
            options: new Array(12).fill('').map((_, index) => ({ label: `${index + 1}月`, value: index + 1 })),
            props: {
              style: {
                width: 120
              }
            }
          },
          dayNum: {
            component: 'Select',
            required: true,
            options: Observer({
              watch: './monthNum',
              action: (monthNum) => {
                console.info('monthNum', monthNum)
                let dayArray: any[] = []
                if (!monthNum) return dayArray
                if (BIG_MOUNTH_ARR.includes(monthNum)) {
                  dayArray = new Array(31).fill('')
                } else if (monthNum === 2) {
                  dayArray = new Array(29).fill('')
                } else {
                  dayArray = new Array(30).fill('')
                }
                return dayArray.map((_, index) => ({ label: `${index + 1}日`, value: index + 1 }))
              }
            }),
            value: Observer({
              watch: './monthNum',
              action: () => null
            }),
            props: {
              style: {
                width: 120
              }
            }
          }
        }
      }
    }
  }

  componentDidMount() {
    // http.get('/api/admin/formation/configSync/list')
  }

  render() {
    return (
      <>
        <div >在编、待入职人数同步时间</div>
        <SchemaForm schema={this.schema} initialValues={{ configSyncRolist: [{}] }}>
          <Item field="configSyncRolist">
            {(fields, _, { errors }) => {
              return (
                <>
                  {
                    fields.map((field) => {
                      const { key, ...restProps } = field
                      return (
                        <Item {...restProps} key={key}>
                          <div style={{ display: 'flex', alignItems: 'baseline' }}>

                            <Item field="monthNum" required={false} />
                            <Item field="dayNum" required={false} />

                          </div>
                        </Item>
                      )
                    })
                  }
                  <ErrorList errors={errors} />
                </>
              )
            }}
          </Item>
        </SchemaForm>
      </>
    )
  }
}
